/**
 * Project:   dtu.fmes.googleloon
 * File:      JsonExporter.java
 * License: 
 *            This file is licensed under GNU General Public License version 3
 *            http://www.gnu.org/licenses/gpl-3.0.txt
 *
 * Copyright: Bartosz Cichecki [ cichecki.bartosz@gmail.com ]
 * Date:      Oct 5, 2013
 */

package dtu.fmes.loon.exporter;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import dtu.fmes.loon.singletons.SimulationStateHistorySingleton;
import dtu.fmes.loon.utils.GsonUtil;

/**
 * 
 * @author Bartosz Cichecki
 */
public class JsonExporter implements Exporter {

	@Override
	public void doExport(File outputFile) throws IOException {
		FileWriter fw = null;

		try {
			fw = new FileWriter(outputFile);
			GsonUtil.buildGson().toJson(SimulationStateHistorySingleton.instance().getSimulationStateHistory(), fw);
		} catch (IOException e) {
			e.printStackTrace();
			throw e;
		} finally {
			if (fw != null) {
				try {
					fw.close();
				} catch (IOException e) {
					e.printStackTrace();
					throw e;
				}
			}
		}
	}

}
